package com.ds.infrastructure.hyperspace.container.internal.transport;

import com.ds.infrastructure.hyperspace.container.internal.HyperspaceThreadFactory;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.ServerSocketChannel;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;

/**
 * @author  Weishaoying
 */
public class JdkNioTransportFactory implements NettyTransportFactory<NioEventLoopGroup> {

    @Override
    public Class<? extends SocketChannel> socketChannelClass() {
        return NioSocketChannel.class;
    }

    @Override
    public Class<? extends ServerSocketChannel> serverSocketChannelClass() {
        return NioServerSocketChannel.class;
    }

    @Override
    public NioEventLoopGroup newEventLoopGroup(HyperspaceThreadFactory threadFactory, int threadNum) {
        return new NioEventLoopGroup(threadNum, threadFactory);
    }

    @Override
    public NioEventLoopGroup newAcceptorEventLoopGroup(HyperspaceThreadFactory threadFactory, int threadNum) {
        NioEventLoopGroup nioEventLoopGroup = newEventLoopGroup(threadFactory, threadNum);
        nioEventLoopGroup.setIoRatio(100);
        return nioEventLoopGroup;
    }

}
